#coding=utf-8
__author__ = 'liubin'

from project.tools import Base
from sqlalchemy import Column, Integer, String, BigInteger, ForeignKey, Boolean, Text
from sqlalchemy.orm import relationship, backref
from sqlalchemy.sql.expression import text
from project.tools import JsonpickleMixin
from base import BaseModel
from textile import Textile


class Material(Textile):
    """
    材料表
    采购回来的布料
    """
    __tablename__ = 'm_material'
    code = Column('code', String(50), nullable=False, doc=u'编码')
    name = Column('name', String(200), nullable=False, doc=u'名称')
    textileId = Column('textile_id', BigInteger, ForeignKey('m_textile.id'), nullable=False, doc=u'布料ID')
    supplierId = Column('textile_id', BigInteger, ForeignKey('m_textile.id'), nullable=False, doc=u'供应商ID')
    isDeleted = Column('is_deleted', Boolean, server_default=text('FALSE'), doc=u'删除标记')

    __mapper_args__ = {
        'polymorphic_identity':'material',
    }

    def __init__(self, data=None):
        """
        初始化
        :param data:
        :return:
        """
        if data:
            self.code = data.get('code')
            self.name = data.get('name')
            self.textileId = data.get('textileId')
            self.supplierId = data.get('supplierId')